//********************************************************************************
// browserStub
// Browser Stub for use with jsTestRunner
// By Nicolas Dextraze
//********************************************************************************

// this is the base for jquery to work
function Element(tagName)
{	
	this.tagName = tagName;
}
Element.prototype = {
	id: "",
	tagName: "",
	innerHTML: "",
	style: {},
	childNodes: [],
	value: "",
	className: "",
	insertBefore: function(elem, beforeThis) {
		var index = -1;
		for( var i=0; i<this.childNodes.length; i++ ) {
			if ( this.childNodes[i] == beforeThis ) {
				index = i;
			}
		}
		if ( index == -1 ) {
			this.appendChild( elem );
			return;
		}
		this.childNodes.splice( index, 0, elem );
	},
	removeChild: function(child) {
		var index = -1;
		for( var i=0; i<this.childNodes.length; i++ ) {
			if ( this.childNodes[i] == child ) {
				index = i;
			}
		}
		if ( index != -1 ) {
			this.childNodes.splice( index, 1 );
		}
	},
	appendChild: function(child) {
		if ( child instanceof Element ) {
			this.childNodes.push( child );
			return;
		}
		print("DEBUG: trying to append a child who's not an instance of Element.");		
	},
	getElementById: function(id) {
		for( var i=0; i<this.childNodes.length; i++ ) {
			if ( this.childNodes[i].id == id ){
				return this.childNodes[i];
			}
		}
		return null;
	},
	getElementsByTagName: function(tagName) {
		var elems = [];
		for( var i=0; i<this.childNodes.length; i++ ) {
			if ( this.childNodes[i].tagName == tagName )
			{
				elems.push( this.childNodes[i] );
			}
		}
		return elems;
	},
	getElementsByClassName: function(className) {
		var elems = [];
		for( var i=0; i<this.childNodes.length; i++ ) {
			if ( this.childNodes[i].className.indexOf(className) != -1 )
			{
				elems.push( this.childNodes[i] );
			}
		}
		return elems;
	},
	createComment: function(comment) {
		var elem = new Element("comment");
		elem.value = comment;
		return elem;
	},
	createTextNode: function(text) {
		var elem = new Element("text");
		elem.value = comment;
		return elem;
	}
};

var window = {};
var navigator = { 
	userAgent: ""
};
var location = {};
var document = new Element("html");
document.documentElement = document;
document.body = new Element("body");
document.createElement = function(tagName) {
	return new Element(tagName);
}

